package com.wangningbo.service;

import com.wangningbo.dao.LinkManDao;
import com.wangningbo.entry.PageBean;
import com.wangningbo.pojo.LinkMan;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author wangningbo
 * @Date 2021/1/10 12:43
 */

public class LinkManService {
    private LinkManDao linkManDao = new LinkManDao();
    public List<LinkMan> findAll() throws SQLException {
        return linkManDao.findAll();
    }

    public void addLinkMan(LinkMan linkMan) throws SQLException {
        linkManDao.addLinkMan(linkMan);
    }

    public void deleteLinkManById(Integer id) throws SQLException {
        linkManDao.deleteLinkManById(id);
    }

    public LinkMan findOne(Integer id) throws SQLException {
        return linkManDao.findOne(id);
    }

    public void updateLinkMan(LinkMan linkMan,Integer id) throws SQLException {
        linkManDao.updateLinkMan(linkMan,id);
    }

    public PageBean findByPage(Long currentPage, Integer pageSize) throws SQLException {
        PageBean pageBean = new PageBean();

        Long totalSize = linkManDao.findTotalSize();
        List<LinkMan> linkManList = linkManDao.findByPage(currentPage,pageSize);
        Long totalPage = totalSize % pageSize == 0 ? totalSize/pageSize : (totalSize/pageSize) + 1 ;
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalSize(totalSize);
        pageBean.setTotalPage(totalPage);
        pageBean.setPageSize(pageSize);
        pageBean.setLinkManList(linkManList);
        return pageBean;
    }
}
